<template>
  <div class="home-view">
    <div class="card-view" v-for="(item, index) in dataList" :key="index">
      <div class="card-label">{{ item.title }}</div>
      <div class="card-list">
        <div
          class="data-list"
          @click="getRouter(item)"
          v-for="(item, idx) in item.list"
          :key="idx"
        >
          <span class="label">
            <span class="label-name">{{ item.name }}</span>
            <span class="msg" v-if="item.msg" :title="item.msg">{{
              item.msg
            }}</span>
          </span>
          <van-icon class="arrow-icon" name="arrow" />
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  watch: {
    $route(to, from) {
      console.log(from.path); // 从哪来
      console.log(to.path); // 到哪去
    },
  },
  data() {
    return {
      dataList: [
        {
          title: "ES6 基础用法",
          list: [
            {
              name: "异步、同步",
              msg: "async、await",
              router: "async",
            },
            {
              name: "节流、防抖",
              msg: "throttle、debounce",
              router: "debounce",
            },
            {
              name: "js 上拉加载 + 图片懒加载",
              msg: "JavaScript + lazy loading",
              router: "lazyLoad",
            },
          ],
        },
        {
          title: "Vue 基础用法",
          list: [
            {
              name: "keep-alive",
              router: "keepAlive",
            },
            {
              name: "component",
              msg: "组件切换",
              router: "component",
            },
            {
              name: "组件通信",
              msg: "传参方式",
              router: "message",
            },
            {
              name: "自定义指令",
              msg: "custom directives",
              router: "directives",
            },
          ],
        },
        {
          title: "Vue 无UI 封装组件 ",
          list: [
            {
              name: "弹窗封装",
              msg: "dialog",
              router: "dialog",
            },
            {
              name: "无限滚动",
              msg: "infiniteScroll",
              router: "infiniteScroll",
            },
            {
              name: "Canvas",
              msg: "Canvas 绘图",
              router: "canvas",
            },
          ],
        },
        {
          title: "npm 插件库使用",
          list: [
            {
              name: "e-charts 组件",
              msg: "使用e-charts 库  - pc and mobile 均可",
              router: "e-charts",
            },
            {
              name: "QRCode",
              msg: "使用qrcode库 生成二维码",
              router: "qrcode",
            },
            {
              name: "js-export-excel",
              msg: "使用js-export-excel库 生成并且下载excel表",
              router: "jsExportExcel",
            },
          ],
        },
        {
          title: "Vue Elemrnt - ui 相关内容",
          list: [
            {
              name: "element-ui tabel组件",
              msg: "使用tablel组件 - pc 端",
              router: "element-tabel",
            },
          ],
        },
      ],
    };
  },
  methods: {
    getRouter(item) {
      this.$router.push({
        name: item.router,
      });
    },
  },
};
</script>
<style lang="scss">
.home-view {
  width: 100%;
  height: 100%;
  .card-view {
    .card-label {
      margin: 0;
      padding: 11px;
      color: rgba(69, 90, 100, 0.6);
      font-weight: normal;
      font-size: 14px;
      line-height: 16px;
    }
    .card-list {
      margin: 0 12px;
      overflow: hidden;
      border-radius: 8px;
      .data-list {
        position: relative;
        display: flex;
        justify-content: space-between;
        box-sizing: border-box;
        width: 100%;
        padding: 8px 16px;
        overflow: hidden;
        color: #323233;
        font-size: 14px;
        background-color: #fff;
        align-items: center;
        ::after {
          position: absolute;
          box-sizing: border-box;
          content: " ";
          pointer-events: none;
          right: 16px;
          bottom: 0;
          left: 16px;
          border-bottom: 1px solid #ebedf0;
          -webkit-transform: scaleY(0.5);
          transform: scaleY(0.5);
        }
        &:last-child {
          ::after {
            content: none;
          }
        }
        .arrow-icon {
          height: 24px;
          font-size: 16px;
          line-height: 24px;
          margin-left: 4px;
          color: #969799;
        }
        .label {
          flex: 1;
          display: flex;
          flex-direction: column;
          .label-name {
            padding: 2px 0;
          }
        }
      }
      .msg {
        font-size: 12px;
        color: #666;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }
  }
}
</style>